/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iftk.xmlparser.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 *
 * @author Tomi
 */
public abstract class BubbleItem {
    
    private static AtomicInteger nextId = new AtomicInteger();
    private final int id;
    private List<Integer> links;
    private String bubbleTitle;
    private String bubbleShort;
    private String bubbleFull;

    public String getBubbleFull() {
        return bubbleFull;
    }

    public void setBubbleFull(String bubbleFull) {
        this.bubbleFull = bubbleFull;
    }

    public String getBubbleShort() {
        return bubbleShort;
    }

    public void setBubbleShort(String bubbleShort) {
        this.bubbleShort = bubbleShort;
    }

    public String getBubbleTitle() {
        return bubbleTitle;
    }

    public void setBubbleTitle(String bubbleTitle) {
        this.bubbleTitle = bubbleTitle;
    }

    public BubbleItem() {
        id = nextId.getAndIncrement();
        links = new ArrayList();
    }

    public List<Integer> getLinks() {
        return links;
    }

    public void setLinks(List<Integer> links) {
        this.links = links;
    }
    
    public int getId() {
        return id;
    }

    public static AtomicInteger getNextId() {
        return nextId;
    }
    
    public void addLink(Integer link) {
        if(!(link < 0)) {
            links.add(link);
        }
    }
    
    public boolean linkExists(Integer link) {
        return links.contains(link);
    }
    
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append(this.getClass().getName()).append("Object {").append(NEW_LINE);
        result.append(" ID: ").append(getId()).append(NEW_LINE);
        result.append(" Links: ");
        for(Integer i : getLinks()) {
            result.append(i).append("\t");
        } 
        result.append(NEW_LINE);        
        result.append("}");
        
        return result.toString();
    }
    
    public String toBubble() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append("<bubble>").append(NEW_LINE);
        result.append("\t<id>").append(getId()).append("</id>").append(NEW_LINE);
        result.append("\t<titletext>").append(bubbleTitle).append("</titletext>").append(NEW_LINE);
        result.append("<titlefontsize>10</titlefontsize>").append(NEW_LINE);
        result.append("\t<shorttext fontsize=\"4\">").append(bubbleShort).append("</shorttext>").append(NEW_LINE);
        //result.append("\t<fulltext>").append(bubbleFull).append("</fulltext>").append(NEW_LINE);
        //result.append("\t<style>Yellow</style>").append(NEW_LINE);
        if(this instanceof CourseList) {
            result.append("\t<style>EitDarkBlue</style>").append(NEW_LINE);
        }
        else if(this instanceof News) {
            result.append("\t<style>Orange</style>").append(NEW_LINE);
        }
        else if(this instanceof Events) {
            result.append("\t<style>White</style>").append(NEW_LINE);
        }
        else if(this instanceof Maps) {
            result.append("\t<style>EitGreen</style>").append(NEW_LINE);
        }
        else if(this instanceof Menus) {
            result.append("\t<style>Purple</style>").append(NEW_LINE);
        }
        else if(this instanceof Personnel) {
            result.append("\t<style>Red</style>").append(NEW_LINE);
        }
        else if(this instanceof ResearchGroups) {
            result.append("\t<style>Black</style>").append(NEW_LINE);
        }
        else if(this instanceof AdvancedCourses || this instanceof BasicCourses ||
                this instanceof Seminars || this instanceof IntermediateCourses ||
                this instanceof DoctorateCourses || this instanceof OtherCourses) {
            result.append("\t<style>EitLightBlue</style>").append(NEW_LINE);
        }
        else if(this instanceof Diner) {
            result.append("\t<style>PinkLevel3</style>").append(NEW_LINE);
        }
        result.append("\t<links>");
        for(int i = 0; i < getLinks().size(); i++) {
            if(i == getLinks().size()-1 && getLinks().size() > 0) {
                result.append(getLinks().get(i));
            }
            else {
                result.append(getLinks().get(i)).append(",");
            }
        }
        result.append("</links>").append(NEW_LINE);
        if(this instanceof CourseList || this instanceof News || 
                this instanceof Events || this instanceof Personnel ||
                this instanceof Maps || this instanceof ResearchGroups || this instanceof Menus) {
            result.append("\t<priority>6</priority>").append(NEW_LINE);
            
        }        
        else {
            result.append("\t<priority>3</priority>").append(NEW_LINE);
        }
        result.append("</bubble>").append(NEW_LINE);
        
        return result.toString();
    }    
}
